<?php

class database {
	private static $instance;
	private $connection;

	private function __construct() {
		$this->connection = pg_connect("
			host=localhost 
			port=5432 
			dbname=headlights 
			user=".PG_USER."
			password=".PG_PASS."
		") or die ("FATAL: Couldn't connect to database");
	}

	public static function getInstance() {
		if(!isset(self::$instance)) {
			$c = __CLASS__;
			self::$instance = new $c;
		}
		return self::$instance;
	}

	public function sqlResult($sql) {
		return pg_query($sql);
	}

	public function singleRow($sql) {
		if($result = self::sqlResult($sql)) {
			return pg_fetch_assoc($result);
		} else {
			return array();
		}
	}
}

?>
